<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>
    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>
</head>

<style>
    .adminInfo{
        position: relative;
        left:33%;
        font-size: 18px;
        padding-top: 5%;
    }
    .row{
        padding-bottom: 20px;
    }
    label{
        font-weight: normal;
    }
    span{
        color: #0b6cbc;
    }
    #confirm{
        position: relative;
        top:0px;
        left:90px;
    }
    #cancel{
        position: relative;
        top:0px;
        left:125px;
    }
</style>


<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">信息修改</strong><small></small></div>
    </div>

    <hr>

    <div class="am-g">
        <form class="adminInfo">
            <div class="row">
                <label>用户名称：</label><input type="text" id="name" disabled></input>
            </div>

            <div class="row">
                <label>邮箱地址：</label><input type="text" id="email">
            </div>

            <div class="row">
                <label>手机号码：</label><input type="text" id="phone">
            </div>

            <div class="row">
                <div>
                    <a class="am-btn am-btn-primary" onclick="confirm()" id="confirm">确认</a>
                    <a class="am-btn am-btn-primary" onclick="cancel()" id="cancel">取消</a>
                </div>
            </div>
        </form>
    </div>
</div>
</body>

<script>
    //id从url得到
    var result = new Object();
    result = getParameter();
    var uid = result["uid"];
    var email = result["email"];
    var phone = result["phone"];
    var name = result["name"];

    $(function () {
        document.getElementById("name").value = name;
        document.getElementById("email").value = email;
        document.getElementById("phone").value = phone;
    })


    function confirm() {
        var email = document.getElementById("email").value;
        var phone = document.getElementById("phone").value;
        $.ajax({
            type: 'post',
            url: '/user/updateUser',
            data: {id: uid, email: email, phone: phone},
            dataType: 'text',
            success: function (mydata) {
                if (mydata == "true") {
                    alert("修改信息成功");
                    window.location.href = "/sellUserMes?uid=" + uid;
                } else {
                    alert("修改信息失败")
                }
            },
            error: function () {
                alert("修改信息失败");
            }
        })
    }

    function cancel() {
        window.location.href = "/sellUserMes?uid=" + uid;
    }

    //解析url传值
    function getParameter() {
        var url = location.search;//获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</html>
